home *** CD-ROM | disk | FTP | other *** search
-
- #include "intern.h"
-
- #ifdef __MTAES__
- #define wind_create_grect(a,b) wind_create(a,b)
- #define wind_calc_grect(a,b,c,d) wind_calc(a,b,c,d)
- #define wind_open_grect(a,b) wind_open(a,b)
- #define wind_set_str(a,b,c) wind_set_string(a,b,c)
- #endif
-
- static WDIALOG *wdial_list = NULL;
-
- /*** lokale Funktionen *********************************************************/
-
- /*
- static void dump_list(void)
- {
- WDIALOG *p;
- int i = 0;
-
- p = wdial_list;
- if (p == NULL)
- debug("Liste ist leer\n");
- while (p != NULL)
- {
- debug("%d: %s\n",i, p->win_name);
- p = p->next;
- i++;
- }
- }
- */
-
-
- /*
- * Liefert zu einem Fensterhandle den Dialog oder NULL.
- */
- static WDIALOG *get_wdial(int w_handle)
- {
- WDIALOG *p;
-
- p = wdial_list;
- while (p != NULL)
- {
- if (p->win_handle == w_handle)
- return p;
- p = p->next;
- }
- return NULL;
- }
-
-
- /*
- * Zeichnet Dialog neu.
- */
- static void draw_wdial(WDIALOG *wd, int obj, int depth, int x, int y, int w, int h)
- {
- GRECT r, r1;
- OBJECT *tree;
-
- r.g_x = x;
- r.g_y = y;
- r.g_w = w;
- r.g_h = h;
-
- if (wd->mode & WD_ICON)
- tree = wd->icon;
- else
- tree = wd->tree;
-
- wind_update(BEG_UPDATE);
- graf_mouse(M_OFF, NULL);
- wind_get_grect(wd->win_handle, WF_FIRSTXYWH, &r1);
- while (r1.g_w != 0 && r1.g_h != 0)
- {
- if (rc_intersect(&r, &r1))
- #ifdef __MTAES__
- objc_draw(tree, obj, depth, &r1);
- #else
- objc_draw(tree, obj, depth, r1.g_x, r1.g_y, r1.g_w, r1.g_h);
- #endif
- wind_get_grect(wd->win_handle, WF_NEXTXYWH, &r1);
- }
- graf_mouse(M_ON, NULL);
- wind_update(END_UPDATE);
- }
-
-
- /*
- * Zeichnet den Cursor neu.
- * Der doppelte objc_edit() ist für den Fall, wenn der Cursor teilweise
- * oder ganz von einem anderen Fenster verdeckt wird.
- */
- static void draw_cursor(WDIALOG *wd, int mode)
- {
- GRECT r;
-
- if (wd != NULL && wd->edit_obj > 0)
- {
- objc_edit(wd->tree, wd->edit_obj, 0, &wd->edit_idx, mode);
- get_objframe(wd->tree, wd->edit_obj, &r);
- draw_wdial(wd, ROOT, MAX_DEPTH, r.g_x, r.g_y-3, r.g_w+1, r.g_h+6);
- objc_edit(wd->tree, wd->edit_obj, 0, &wd->edit_idx, mode);
- }
- }
-
-
- static void move_wdial(WDIALOG *wd, int new_x, int new_y)
- {
- if (wd != NULL)
- {
- GRECT r;
-
- wind_get_grect(wd->win_handle, WF_CURRXYWH, &r);
- r.g_x = new_x;
- r.g_y = new_y;
- wind_set_grect(wd->win_handle, WF_CURRXYWH, &r);
- wind_get_grect(wd->win_handle, WF_WORKXYWH, &r);
-
- if (wd->mode & WD_ICON)
- {
- wd->icon[0].ob_x = r.g_x;
- wd->icon[0].ob_y = r.g_y;
- }
- else
- {
- wd->tree[0].ob_x = r.g_x;
- wd->tree[0].ob_y = r.g_y - wd->delta_y;
- wd->work.g_x = r.g_x;
- wd->work.g_y = r.g_y;
- wd->work.g_w = r.g_w;
- wd->work.g_h = r.g_h;
- }
- }
- }
-
-
- static void iconify_wdial(WDIALOG *wd, int x, int y, int w, int h)
- {
- if (wd->icon && !(wd->mode & WD_ICON))
- {
- /* alte Größe merken */
- wind_get_grect(wd->win_handle, WF_CURRXYWH, &wd->work);
-
- wind_set(wd->win_handle, WF_ICONIFY, x, y, w, h);
- wind_get(wd->win_handle, WF_WORKXYWH, &x, &y, &w, &h);
- wd->icon[0].ob_x = x;
- wd->icon[0].ob_y = y;
- wd->icon[0].ob_width = w;
- wd->icon[0].ob_height = h;
- wd->icon[1].ob_x = (w - wd->icon[1].ob_width) / 2;
- wd->icon[1].ob_y = (h - wd->icon[1].ob_height) / 2;
- wd->mode |= WD_ICON;
- }
- }
-
-
- static void uniconify_wdial(WDIALOG *wd, int x, int y, int w, int h)
- {
- if (wd->mode & WD_ICON)
- {
- if (x == -1)
- wind_set_grect(wd->win_handle, WF_UNICONIFY, &wd->work);
- else
- wind_set(wd->win_handle, WF_UNICONIFY, x, y, w, h);
- wind_get_grect(wd->win_handle, WF_WORKXYWH, &wd->work);
- wd->mode &= ~WD_ICON;
- }
- }
-
-
- /*
- * Ruft Exit-Callback auf und schließ ggf. den Dialog.
- */
- static void call_cb(WDIALOG *wd)
- {
- int close = TRUE;
- int obj;
-
- obj = wd->next_obj;
- if (wd->exit_cb != NULL)
- close = (wd->exit_cb)(wd, obj);
- if (close)
- {
- obj &= 0x7FFF;
- if (obj != WD_CLOSER)
- set_state(wd->tree, obj, SELECTED, FALSE);
- close_wdial(wd);
- }
- }
-
-
- /*** exportierte Funktionen ****************************************************/
-
- /*
- * Dialog vorbereiten.
- */
- WDIALOG *create_wdial(OBJECT *tree, OBJECT *icon, int edit_obj,
- WDIAL_OCB open_cb, WDIAL_XCB exit_cb)
- {
- WDIALOG *new;
- int d;
-
- new = (WDIALOG *) cf_malloc(sizeof(WDIALOG), "create_wdial", FALSE);
- if (new != NULL)
- {
- /* in die Liste hängen */
- new->next = wdial_list;
- wdial_list = new;
-
- new->tree = tree;
- new->icon = icon;
- new->mode = 0;
- new->win_handle = -1;
- if (new->icon == NULL)
- new->win_kind = (NAME|MOVER|CLOSER);
- else
- new->win_kind = (NAME|MOVER|CLOSER|SMALLER);
-
- /*
- * Titelzeile suchen und als Fenstertitel merken.
- */
- if (get_magx_obj(tree, 1) == MX_UNDERLINE)
- {
- new->title_obj = 1;
- get_string(tree, new->title_obj, new->win_name);
- }
- else
- {
- new->title_obj = -1;
- strcpy(new->win_name, "*** kein Titel! ***");
- }
-
- /*
- * Gibt es ein Abbruch-Button? -> Closer
- */
- d = find_flag(tree, FLAG11);
- if (d != -1)
- new->cancel_obj = d;
- else
- new->cancel_obj = WD_CLOSER;
-
- new->next_obj = 0;
- if ((edit_obj <= 0) || !edit_valid(new->tree, edit_obj))
- new->edit_obj = find_edit(new->tree, 0, FMD_FORWARD);
- else
- new->edit_obj = edit_obj;
- new->edit_idx = 0;
-
- new->open_cb = open_cb;
- new->exit_cb = exit_cb;
- }
- return new;
- }
-
-
- /*
- * Dialog entfernen.
- */
- void delete_wdial(WDIALOG *wd)
- {
- if (wd != NULL)
- {
- WDIALOG *p;
-
- if (wd->win_handle > 0)
- {
- close_wdial(wd);
- wind_delete(wd->win_handle);
- wd->win_handle = -1;
- }
-
- /* aus Liste löschen */
- if (wd == wdial_list) /* erster? */
- wdial_list = wd->next;
- else
- {
- p = wdial_list;
- while (p->next != NULL && p->next != wd)
- p = p->next;
- p->next = wd->next;
- }
- Mfree(wd);
- }
- }
-
-
- /*
- * Dialog-Fenster öffnen.
- */
- void open_wdial(WDIALOG *wd, int pos_x, int pos_y)
- {
- GRECT r1, r2;
- int d;
-
- if (wd != NULL)
- {
- if (wd->mode == WD_OPEN) /* ist schon offen */
- {
- wind_set(wd->win_handle, WF_TOP, 0, 0, 0, 0);
- return;
- }
- if (wd->mode & WD_ICON) /* ist iconified */
- {
- uniconify_wdial(wd, -1, 0, 0, 0);
- return;
- }
- if (wd->mode & WD_SHADE) /* ist shaded */
- {
- wind_set(wd->win_handle, WF_SHADE, 0, 0, 0, 0);
- wd->mode &= ~WD_SHADE;
- return;
- }
- else if (wd->win_handle > 0) /* war schon mal offen */
- {
- if (wd->open_cb != NULL)
- (wd->open_cb)(wd);
- wind_calc_grect(WC_BORDER, wd->win_kind, &wd->work, &r1);
- wind_open_grect(wd->win_handle, &r1);
- wd->mode = WD_OPEN;
- return;
- }
- else /* alles neu */
- {
- /* Rahmen abschalten */
- wd->tree[0].ob_spec.obspec.framesize = 0;
-
- if ((pos_x == -1) || (pos_y == -1)) /* Zentrieren */
- #ifdef __MTAES__
- form_center(wd->tree, &r1);
- #else
- form_center(wd->tree, &r1.g_x, &r1.g_y, &r1.g_w, &r1.g_h);
- #endif
- else
- {
- wd->tree[0].ob_x = pos_x;
- wd->tree[0].ob_y = pos_y;
- }
-
- r1.g_x = wd->tree[0].ob_x;
- r1.g_y = wd->tree[0].ob_y;
-
- /* Titel nicht mitzeichnen */
- if (wd->title_obj != -1)
- {
- wd->delta_y = (wd->tree[wd->title_obj].ob_y + wd->tree[wd->title_obj].ob_height);
- wd->tree[0].ob_y -= wd->delta_y;
- set_flag(wd->tree, wd->title_obj, HIDETREE, TRUE);
- }
- else
- wd->delta_y = 0;
-
- r1.g_w = wd->tree[0].ob_width;
- r1.g_h = wd->tree[0].ob_height - wd->delta_y;
-
- wind_calc_grect(WC_BORDER, wd->win_kind, &r1, &r2);
-
- /* Fenster neu zentrieren */
- d = (r2.g_h - r1.g_h) / 2 + wd->delta_y / 2;
- r2.g_y += d ;
- wd->tree[0].ob_y += d;
- /* herausragen ins Menü verhindern */
- if (r2.g_y < gl_desk.g_y)
- {
- wd->tree[0].ob_y += (gl_desk.g_y - r2.g_y);
- r2.g_y = gl_desk.g_y;
- }
-
- wd->win_handle = wind_create_grect(wd->win_kind, &r2);
- if (wd->win_handle > 0)
- {
- wind_set_str(wd->win_handle, WF_NAME, wd->win_name);
- if (wd->open_cb != NULL)
- (wd->open_cb)(wd);
- wind_open_grect(wd->win_handle, &r2);
- wind_calc_grect(WC_WORK, wd->win_kind, &r2, &wd->work);
- wd->mode = WD_OPEN;
- }
- else
- form_alert(1, "[3][wdial.Open:|Kein Fenster mehr frei!][oops]");
- }
- }
- }
-
-
- /*
- * Dialog-Fenster schließen.
- */
- void close_wdial(WDIALOG *wd)
- {
- if (wd != NULL)
- {
- if ((wd->win_handle > 0) && (wd->mode & WD_OPEN))
- {
- wind_close(wd->win_handle);
- wd->mode = 0;
- }
- }
- }
-
-
- /*
- * Einzelne Objekte neu zeichnen.
- */
- void redraw_wdobj(WDIALOG *wd, int obj)
- {
- GRECT r;
-
- if (wd != NULL && !(wd->mode & WD_ICON) && !(wd->mode & WD_SHADE))
- {
- get_objframe(wd->tree, obj, &r);
- draw_wdial(wd, ROOT, MAX_DEPTH, r.g_x, r.g_y, r.g_w, r.g_h);
-
- /* neu zeichnen, wenn obj das Editfeld bzw. ein Child von obj ist */
- if ((obj == wd->edit_obj) ||
- (wd->edit_obj >= wd->tree[obj].ob_head && wd->edit_obj <= wd->tree[obj].ob_tail))
- draw_cursor(wd, ED_INIT);
- }
- }
-
- /*
- * Ein Objekt im iconified Dialog zeichnen.
- */
- void redraw_wdicon(WDIALOG *wd, int obj)
- {
- GRECT r;
-
- if (wd != NULL && wd->mode & WD_ICON)
- {
- get_objframe(wd->icon, obj, &r);
- draw_wdial(wd, ROOT, MAX_DEPTH, r.g_x, r.g_y, r.g_w, r.g_h);
- }
- }
-
- /*
- * Cursor updaten
- */
- void change_wdedit(WDIALOG *wd, int new)
- {
- int last = 0;
-
- if (wd != NULL)
- {
- /* 1. prüfen, ob aktuelles nicht mehr gültig ist */
- if (wd->edit_obj > 0)
- {
- last = -1;
- if (!edit_valid(wd->tree, wd->edit_obj))
- {
- objc_edit(wd->tree, wd->edit_obj, 0, &wd->edit_idx, ED_END);
- last = wd->edit_obj;
- }
- }
-
- /*
- * last = -1 -> aktuelles Editfeld weiterhin gültig, nix weiteres tun
- * last = 0 -> bisher kein Editfeld, erstes suchen
- * last > 0 -> aktuelles Editfeld ungültig geworden, nächstes suchen
- */
- if (last != -1)
- {
- if (new > 0 && edit_valid(wd->tree, new))
- wd->edit_obj = new; /* 2a. ein gültiges neues übergeben? */
- else /* 2b. neues suchen */
- wd->edit_obj = find_edit(wd->tree, last, FMD_FORWARD);
- if (wd->edit_obj > 0)
- objc_edit(wd->tree, wd->edit_obj, 0, &wd->edit_idx, ED_INIT);
- }
- }
- }
-
-
- /*
- * Event-Verarbeitung.
- */
- int message_wdial(int *msg)
- {
- int ret = TRUE;
- WDIALOG *wd;
-
- wd = get_wdial(msg[3]);
- if (wd != NULL)
- {
- switch (msg[0])
- {
- case WM_REDRAW :
- draw_wdial(wd, ROOT, MAX_DEPTH, msg[4], msg[5], msg[6], msg[7]);
- draw_cursor(wd, ED_INIT);
- break;
-
- case WM_MOVED:
- move_wdial(wd, msg[4], msg[5]);
- break;
-
- case WM_TOPPED:
- wind_set(wd->win_handle, WF_TOP, 0, 0, 0, 0);
- break;
-
- case WM_BOTTOMED:
- wind_set(wd->win_handle, WF_BOTTOM, 0, 0, 0, 0);
- break;
-
- case WM_ICONIFY :
- iconify_wdial(wd, msg[4], msg[5], msg[6], msg[7]);
- break;
-
- case WM_UNICONIFY :
- uniconify_wdial(wd, msg[4], msg[5], msg[6], msg[7]);
- break;
-
- case WM_SHADED :
- wd->mode |= WD_SHADE;
- break;
-
- case WM_UNSHADED :
- wd->mode &= ~WD_SHADE;
- break;
-
- case WM_CLOSED :
- wd->next_obj = wd->cancel_obj;
- call_cb(wd);
- break;
-
- case WM_UNTOPPED :
- case WM_ONTOP :
- case WM_NEWTOP:
- /* ignore */
- break;
-
- default:
- ret = FALSE;
- }
- }
- else
- ret = FALSE;
- return ret;
- }
-
-
- int click_wdial(int clicks, int x, int y, int kshift, int mbutton)
- {
- int wh;
- int ret = TRUE, cont;
- int obj;
- WDIALOG *wd;
-
- wh = wind_find(x, y);
- wd = get_wdial(wh);
- if (wd != NULL && wd->mode == WD_OPEN)
- {
- if (mbutton == 1)
- {
- obj = cf_objc_find(wd->tree, ROOT, MAX_DEPTH, x, y);
- if (obj > -1)
- {
- cont = form_button(wd->tree, obj, clicks, &wd->next_obj);
- if (cont && (get_flag(wd->tree, wd->next_obj, EDITABLE)))
- {
- objc_edit(wd->tree, wd->edit_obj, 0, &wd->edit_idx, ED_END);
- wd->edit_obj = wd->next_obj;
- if (gl_magx)
- objc_edit(wd->tree, wd->edit_obj, x, &wd->edit_idx, ED_CRSR);
- else
- objc_edit(wd->tree, wd->edit_obj, 0, &wd->edit_idx, ED_INIT);
- }
- else if (!cont)
- {
- if (clicks == 2)
- wd->next_obj |= 0x8000;
- call_cb(wd);
- }
- }
- else
- Bconout(2, 7);
- }
- else if (mbutton == 2) /* Rechtsklick ignorieren */
- ret = TRUE;
- }
- else
- ret = FALSE;
- return ret;
- }
-
-
- int key_wdial(int kreturn, int kstate)
- {
- int wh, d;
- int ret = TRUE, cont, ctrl;
- WDIALOG *wd;
-
- wind_get(0, WF_TOP, &wh, &d, &d, &d);
- wd = get_wdial(wh);
- if (wd != NULL && wd->mode == WD_OPEN)
- {
- cont = cf_form_keybd(wd->tree, wd->edit_obj, kstate, &kreturn, &wd->next_obj);
- if (cont)
- {
- if (kreturn)
- cf_objc_edit(wd->tree, wd->edit_obj, kreturn, &wd->edit_idx, ED_CHAR, kstate, &ctrl);
- else if (cont && (wd->tree[wd->next_obj].ob_flags & EDITABLE))
- {
- objc_edit(wd->tree, wd->edit_obj, 0, &wd->edit_idx, ED_END);
- wd->edit_obj = wd->next_obj;
- objc_edit(wd->tree, wd->edit_obj, 0, &wd->edit_idx, ED_INIT);
- }
- }
- else
- call_cb(wd);
-
- /* alle Ctrl-Codes außer ^X^C^V werden nicht ausgewertet */
- if ((kstate & K_CTRL) && !ctrl)
- ret = FALSE;
- }
- else
- ret = FALSE;
-
- return ret;
- }
-